import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams ,ViewController,LoadingController} from 'ionic-angular';

import {UserService} from "../../providers/UserService";
import {UserInfo} from "../../model/UserInfo";

import {StorageService} from "../../providers/StorageService";
import {USERFACE_PATH} from "../../providers/Constants";

@IonicPage()
@Component({
  selector: 'page-user-info',
  templateUrl: 'user-info.html',
})
export class UserInfoPage {

  errorMessage:any;
  constructor(public navCtrl: NavController,
              public navParams: NavParams,
              public userService :UserService,
              public userInfo :UserInfo,
              public  viewCtrl : ViewController,
              public  storageService:StorageService,
              public loadingCtrl :LoadingController) {
  }


  ionViewDidEnter() {
    this.loadUserInfoPage();
  }

  loadUserInfoPage(){
    let loader = this.loadingCtrl.create({content: "正在获取获取数据...",});
    loader.present();
    var id =this.storageService.read<UserInfo>('UserInfo').id ;
    this.userService.getUserInfo(id).subscribe(
      res=>{
        if(res["status"]==0){
          this.userInfo=res["data"];
          this.userInfo.userFace=USERFACE_PATH+"/"+this.userInfo.userFace;
          console.log(this.userInfo);
        }else {
          this.viewCtrl.dismiss();
        }

      },
      error => this.errorMessage = <any>error);
    loader.dismiss();
  }
  //注销
  logout() {
    this.storageService.remove('UserInfo');
    this.viewCtrl.dismiss();
  }

}
